<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-11-28
 * Time: 16:35
 */

namespace app\src\goods\helper;


use app\src\base\exception\BusinessException;

class PriceHelper
{
    static public function getSkuPrice($sku,$count){

        $price  = 0;
        $cnt1   = empty($sku['cnt1']) ? 0 : $sku['cnt1'];
        $cnt2   = empty($sku['cnt2']) ? 0 : $sku['cnt2'];
        $cnt3   = empty($sku['cnt3']) ? 0 : $sku['cnt3'];
        $price1 = $sku['price'];
        $price3 = $sku['price3'];
        $price2 = $sku['price2'];

        if($count < $cnt1){
            throw  new BusinessException(lang("err_cart_item_count_invalid",['name'=>'','min'=>$cnt1]));
        }

        //注意处理cnt3 等于0的情况，默认等于0为没有该价格，或无穷大
        if($count >= $cnt3 && $cnt3 > 0){
            $price = $price3;
        }elseif ($count >= $cnt2 && $cnt2 > 0){
            $price = $price2;
        }elseif($count >= $cnt1){
            $price = $price1;
        }

        return $price;
    }
}